//= require prevent_label

/*
 * smart admin
 * DO NOT REMOVE : GLOBAL FUNCTIONS!
*/
$(document).ready(function() {
  pageSetUp();
  // PAGE RELATED SCRIPTS

  $('.tree > ul').attr('role', 'tree').find('ul').attr('role', 'group');
  $('.tree').find('li:has(ul)').addClass('parent_li').attr('role', 'treeitem').find(' > span').attr('title', 'Collapse this branch').on('click', function(e) {
    var children = $(this).parent('li.parent_li').find(' > ul > li');
    if (children.is(':visible')) {
      children.hide('fast');
      $(this).attr('title', 'Expand this branch').find(' > i').removeClass().addClass('fa fa-lg fa-plus-circle');
    } else {
      children.show('fast');
      $(this).attr('title', 'Collapse this branch').find(' > i').removeClass().addClass('fa fa-lg fa-minus-circle');
    }
    e.stopPropagation();
  });
});

/*
 * lazybox
*/

$(document).ready(function() {
  $('a[rel*=lazybox]').lazybox();
  // or with options
  $('a[rel*=lazybox]').lazybox({overlay: true, esc: true, close: true, modal: true, klass: 'modal-dialog'});
});

$.lazybox.settings = {cancelClass: "button gray", submitClass: 'button gray', overlay: false, opacity: 0.5};

/*
 * lightbox
 */
$(document).ready(function() {
  // delegate calls to data-toggle="lightbox"
  $(document).delegate('*[data-toggle="lightbox"]', 'click', function(event) {
      event.preventDefault();
      return $(this).ekkoLightbox({
          onShown: function() {
              if (window.console) {
                  return console.log('Checking our the events huh?');
              }
          }
      });
  });
})

/*
 * datepicker
*/
$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
$(document).ready(function(){
  $('input.ui-date-picker').datepicker();
  // $('input.ui-datetime-picker').datetimepicker();
});